jQuery(document).ready(function(){
	
	$j("#managegroup_controll").bind("click", function(){	
		$j("#managegroups").fadeIn("fast");
	});

	$j("#close_mgroup").bind("click", function(){	
		$j("#managegroups").fadeOut("fast");
	});

	$j("#manageg_not").bind("click", function(){	
		$j("#managegroups").fadeOut("fast");
	});

	$j("#manageg_ok").bind("click", function(){	
		
		var pageelements = $j("#group").attr("value");
	
		if ( pageelements == "first" )
		{
			
			$j("#groupmessage_alert").text( "You need to choose valid group! 'Choose...' is not answer which we require :)" ).show().fadeIn();
		}
		else{
			$j("#groupmessage_alert").fadeOut("fast");
			$j("#progress #pmessage").text("Please wait...");
			$j("#progress").fadeIn("slow");
			$j("#managegroups").fadeOut("fast");
			setTimeout('document.location="'+baseLoc+pageelements+'"', 1000 );
		}
	});
	
	
	
	$j("#deletegroup_controll").bind("click", function(){	
		$j("#deletegroup_box").fadeIn("fast");
	});

	$j("#close_dgroup").bind("click", function(){	
		$j("#deletegroup_box").fadeOut("fast");
	});

	$j("#deleteg_not").bind("click", function(){	
		$j("#deletegroup_box").fadeOut("fast");
	});

	$j("#deleteg_ok").bind("click", function(){	
		var pageelements = $j("#group2").attr("value");
	
		if ( pageelements == "first" )
		{
			
			$j("#groupmessage_alert2").text( "You need to choose valid group! 'Choose...' is not answer which we require :)" ).show().fadeIn();
		}
		else{
			$j("#deletegroup_box").fadeOut("fast");
			$j("#progress #pmessage").text("Please wait...");
			$j("#progress").fadeIn("slow");
			var action = $j("#deletegroup_form").attr("action") + $j("#group2").attr("value");

			$j.ajax({
				type: "POST",
				url:  action,
				data: "status=allowed",
				dataType: "json",
				success: function ( data, status ){
					
					if ( data.status == "false" )
					{
						$j("#progress").addClass("progress-error");
						$j("#progress #pmessage").text(data.message);
					}
					else if ( data.status == "true" )
					{
						$j("#progress").removeClass("progress-error");
						$j("#progress #pmessage").text(data.message);
						setTimeout('$j("#progress").fadeOut("normal");location.reload(true);', 3000 );
					}
					
				}
			});
			
		}
	});	
	
	$j("#managemi_controll").bind("click", function(){	
		$j("#manageimages").fadeIn("fast");
	});

	$j("#managemi_ok").bind("click", function(){	
		$j("#mimessage_alert").text("Please wait.... System will now redirect you to manage area for choosen image!").fadeIn("slow");
		var link = $j("#managemigroup_form").attr("action") + $j("#miselection").attr("value");
		setTimeout ( 'document.location="'+link+'storage"', 3000 );	
	});
	
	$j("#close_migroup").bind("click", function(){	
		$j("#manageimages").fadeOut("fast");
	});

	$j("#managemi_not").bind("click", function(){	
		$j("#manageimages").fadeOut("fast");
	});
});